<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: header('新增DI信息')"/>
    <link rel="stylesheet" href="../../../static/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../../static/ajax/libs/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" href="../../../static/udi/dist/css/layui.css">
</head>
<body>
<div class="container-fluid">
    <div class="panel" style="width: 100%">
        <div class="panel-heading" style="margin: 5px;background-color:	#F5F5F5">
            <p><b>注意</b>:xxx</p>
        </div>
        <div class="panel-body">
            <form id="form-di-add" class="form-horizontal m">
                <div class="form-group">
                    <label class="col-sm-2 control-label">企业名称：</label>
                    <div class="col-sm-9">
                        <select name="deptId" id="deptName" class="form-control input-sm" required></select>
                    </div>
                </div>
                <input id="corpCode" name="corpCode" hidden/>
                <input id="hide" hidden/>
                <div class="form-group">
                    <label class="col-sm-2 control-label">编码类型选择：</label>
                    <div class="col-sm-9">
                        <select id="code_type" name="type" class="form-control input-sm" required></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">生成数量：</label>
                    <div class="col-sm-9">
                        <input name="num" id="num" class="form-control input-sm" autocomplete="off" placeholder="填写整数" required>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<!--<script src="../../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../../../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
<script src="../../../static/ajax/libs/bootstrap-table/bootstrap-table.min.js" th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
<script src="../../../static/udi/dist/layui.js" th:src="@{/udi/dist/layui.js}"></script>-->
<script th:inline="javascript">
    $(function () {
        /*部门下拉列表*/
        $.get("/dimange/getDeptMes",{},function (res) {
            $("#deptName").empty();
            $("#hide").attr('value',JSON.stringify(res));
            $("#corpCode").attr('value',res[0].corpCode);
            $.each(res,function (i,o) {
                $("#deptName").append('<option value='+o.deptId+'>'+o.deptName+'</option>');
            })
        });
        /*包装指示符列表*/
        $.get("/dimange/selectpkg",{},function (res) {
            $("#code_type").empty();
            $.each(res,function (i,o) {
                $("#code_type").append('<option value='+o.pkg+'>'+o.pkginfo+'</option>');
            })
        });

        $('#deptName').on('change',function () {
            $.each(JSON.parse($("#hide").val()),function (i,o) {
                if($("#deptName").val()===o.deptId){
                    $("#corpCode").attr("value",o.corpCode);
                }
            })

        })
        $("#form-di-add").validate({
            onkeyup: false,
            rules:{
                num:{
                    positiveinteger: true
                }
            },
            messages: {
                num:{
                    positiveinteger: "必须输入正整数！"
                }
            },
            focusCleanup: true//当表单得到焦点时，移除在该表单上的errorClass并隐藏所有错误消息
        });
    })

    // 添加自定义校验规则，校验正整数
    $.validator.addMethod("positiveinteger", function(value, element) {
        var Val = parseInt(value);
        return Val > 0 && (Val + "") == value;
    }, "请输入正整数");

    //主页面数据提交开始生成DI码
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save("/digener/add", $('#form-di-add').serialize());
        }
    }

    //格式化日期
    function getNowFormatDate() {
        var now = new Date();
        var date = now.getFullYear()
                + "-" + (now.getMonth()>8?(now.getMonth()+1):"0"+(now.getMonth()+1))
                + "-" + (now.getDate()>9?now.getDate():"0"+now.getDate())
                + " " + (now.getHours()>9?now.getHours():"0"+now.getHours())
                + ":" + (now.getMinutes()>9?now.getMinutes():"0"+now.getMinutes())
                + ":" + (now.getSeconds()>9?now.getSeconds():"0"+now.getSeconds());
        return date;
    }
</script>
</body>
</html>